package 最大子段和;

import java.util.Scanner;

public class Main {
    static int N = 200010;
    static long[] f = new long[N];

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        long res = Integer.MIN_VALUE;
        for (int i = 1; i <= n; i++) {
            f[i] = in.nextInt();
            if (f[i - 1] > 0) {
                f[i] += f[i - 1];
            }
            res = Math.max(res, f[i]);
        }
        System.out.println(res);
    }
}
